let express = require("express");

// ****1-创建一个路由中间件，来管理 文章相关的路由

let router = express.Router();
let _ = require("lodash");

// ****2-在文章路由中间件 处理 文章相关的路由操作

// 1-获取所有文章，pagenum pagesize 分页，返回 接口 参数值
// get /articles?pagenum=1

router.get("/recentUserNum", (req, res) => {
  let now = new Date();
  let d1 = new Date();
  let d2 = new Date(now.getDate() - 1);
  let d3 = new Date(now.getDate() - 2);

  res.json({
    params: req.query,
    msg: "最近几天的注册量",
    data: [
      { time: d1, num: _.random(1000, 100000000) },
      { time: d2, num: _.random(1000, 100000000) },
      { time: d3, num: _.random(1000, 100000000) },
    ],
  });
});
router.get("/recentProductNum", (req, res) => {
  let now = new Date();
  let d1 = new Date();
  let d2 = new Date(now.getDate() - 1);
  let d3 = new Date(now.getDate() - 2);
  res.json({
    params: req.query,
    msg: "最近几天的商品销量统计",
    data: [
      { time: d1, salesNum: _.random(1000, 100000000) },
      { time: d2, salesNum: _.random(1000, 100000000) },
      { time: d3, salesNum: _.random(1000, 100000000) },
    ],
  });
});

router.get("/productSort", (req, res) => {
  let now = new Date();
  let d1 = new Date();
  let d2 = new Date(now.getDate() - 1);
  let d3 = new Date(now.getDate() - 2);
  res.json({
    params: req.query,
    msg: "最近几天的商品销量排行",
    data: [
      { name: "男装", salesNum: _.random(100000, 2220000) },
      { name: "女装", salesNum: _.random(100000, 2220000) },
      { name: "化妆品", salesNum: _.random(100000, 2220000) },
      { name: "手机", salesNum: _.random(100000, 2220000) },
      { name: "电脑", salesNum: _.random(100000, 2220000) },
      { name: "手机配件", salesNum: _.random(100000, 2220000) },
      { name: "母婴", salesNum: _.random(100000, 2220000) },
      { name: "男鞋", salesNum: _.random(100000, 2220000) },
      { name: "女鞋", salesNum: _.random(100000, 2220000) },
    ],
  });
});

let allUserNum = _.random(10000, 222000);
let allOrderNum = _.random(10000, 222000);
router.get("/currentNum", (req, res) => {
  allUserNum += _.random(-500, 1000);
  allOrderNum += _.random(100, 1000);
  res.json({
    params: req.query,
    msg: "实时在线用户数据，实时订单量",
    data: {
      allUserNum: allUserNum,
      allOrderNum,
    },
  });
});
// ******3-导出文章路由中间件
module.exports = router;
